package ms.maplestory.boot.client.character.quest.requirement;

import lombok.Getter;
import lombok.Setter;
import ms.maplestory.boot.client.character.Char;
import ms.maplestory.boot.enums.CharStatFlag;
import ms.maplestory.boot.loaders.DatSerializable;
import ms.maplestory.boot.service.helpers.CharHelper;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;

@Getter
@Setter
public class QuestStartMinStatRequirement implements QuestStartRequirement {

    private CharStatFlag stat;
    private int reqAmount;


    public QuestStartMinStatRequirement() {

    }

    public QuestStartMinStatRequirement(CharStatFlag stat, int reqAmount) {
        this.reqAmount = reqAmount;
        this.stat = stat;
    }

    @Override
    public boolean hasRequirements(Char chr) {
        return CharHelper.getCharStat(chr, getStat()) >= getReqAmount();
    }

    @Override
    public void write(DataOutputStream dos) throws IOException {
        dos.writeInt(stat.getValue());
        dos.writeInt(getReqAmount());
    }

    @Override
    public DatSerializable load(DataInputStream dis) throws IOException {
        return new QuestStartMinStatRequirement(CharStatFlag.getByValue(dis.readInt()), dis.readInt());
    }
}
